package io.coderyeah.system.listener;

import io.coderyeah.system.service.PermissionService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;

/**
 * 自定义上下文监听器
 * 应用启动时就自动创建一个上下文对象
 * 自动执行监听器的内容
 */
@WebListener//表示监听器
@Slf4j
public class PermissionScanInitListener implements ServletContextListener {
    @Autowired
    private PermissionService permissionService;

    @Override
    public void contextInitialized(ServletContextEvent sce) {
        new Thread(() -> {
            log.info("===========权限初始化开始=============");
            permissionService.scanPermission();
            log.info("=========权限初始结束============");
        }).start();
    }

    @Override
    public void contextDestroyed(ServletContextEvent sce) {

    }
}
